package com.zeropoint.demo.pojo;


import com.zeropoint.demo.common.Disable;
import com.zeropoint.demo.pojo.vo.*;
import com.zeropoint.demo.util.ArrayUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.ArrayList;


/**
 * 权重计算
 */
@ToString
@AllArgsConstructor
@Data
@NoArgsConstructor
public class WeightAlgorithm {

    //家中是否有小汽车
    public boolean isCar;
    //是否村外购房
    public boolean isHouse;
    //年龄
    public int age;
    //家庭人数
    public int families;
    //劳动力残疾
    public double labor;
    //人均健康
    public double health;

    //19-60岁残疾人数 新
    public double numberOfAged19_60_disability;
    //残疾类型 新
    public double disable_style;
    //家庭残疾人数已存在
    //村外购房 新
    public double other_housing;
    //购房面积 新
    public double other_house_area;
    //小汽车 新
    public double car_number;
    //金融性资产 新
    public double financialAssets;
    //抚养费 新
    public double alimony;
    //人均收入
    //(不含补助）新
    public double perCapitaIncomeN;
    //人均收入
    //（含补助）新
    public double perCapitaIncome;
    //个体经营收入 新
    public double individualBusinessIncome;
    //家庭子女每年教育支出 新
    public double educationOutCome;
    //重大疾病每年医疗支出 新
    public double bigHealthSpending;
    //重大疾病个人医疗支出 新
    public double bigPersonMoney;
    //慢性疾病个人负担 新
    public double slowPersonMoney;
    //近一年突发性事件支出 新
    public double emergentEventMoney;
    //家庭人均支出 新
    public double perHouseholdExpenditure;
    //人均收支 新
    public double perExpenditure;
    //最低生活保障 新
    public double minLivingSecurity;
    //人均收入（不含补助）-最低生活保障 新
    public double minLivingSecurity_;
    //人均收支-1倍最低生活保障 新
    public double minLivingSecurity__;
    //人均收支-1.5倍最低生活保障 新
    public double minLivingSecurity___;

    //股票
    public double stock;
    //家庭残疾人数
    public int disabilitiesNumber;

    //劳动力数
    public double laborNumber;
    //主要劳动力占比
    public double laborProportion;
    //文化程度
    public double educationLevel;
    //健康状况
    public double healthStatus;
    //就业状况
    public double employmentStatus;
    //宅基地数
    public double homesteadNumber;
    //耕地资源
    public double cultivatedLandResources;
    //林地资源
    public double forestResources;
    //住房来源
    public double housingSource;
    //住房面积
    public double housingArea;
    //额外购房
    public double additionalPurchase;
    //耐用消费品
    public double durableGoods;
    //经营性收入
    public double operatingIncome;
    //工资性收入
    public double wageIncome;
    //转移性收入
    public double transferIncome;
    //财产性收入
    public double propertyIncome;
    //家庭成员担任村组干部
    public double groupCadres;
    //发生困难时得到他人帮助
    public double getHelp;
    //家庭日常通讯费用
    public double dailyCommunicationExpenses;
    //家庭成员参与社会组织
    public double socialOrganizations;
    // 家庭成员参与社会保险
    public double socialInsurance;
    // 是否享受政策贴息贷款
    public double discountLoan;
    // 是否向亲戚朋友处借款
    public double borrowMoney;
    // 人情往来支出
    public double humanExpenditure;
    // 人情外来次数
    public double numberOfOutsiders;

    //评定结果
    public double result;

    public WeightAlgorithm(Questionnaire_info info, FormOne one, FormTwo two,  FormThree three, FormFour four, HumanResourceStandardized h
    , NaturalResourceStandardized n, MaterialResourceStandardized m, FamilyIncomeStandardized i
    , SocialResourceStandardized s, FamilyOutcomeStandardized o){

        isCar = two.car_number >= 1;

        isHouse = !"没有".equals(two.other_housing);

        age = one.user_age;

        families = one.total_people_num;

        labor = h.disabilityRatio;

        health = h.healthAssignment;

        numberOfAged19_60_disability = h.numberOfAged19_60_disability;

        if(ArrayUtils.isContains(h.numberOfAged19_60_disabled_info, Disable.ZHILI.name)){
            disable_style = Disable.ZHILI.flag;
        }else if(ArrayUtils.isContains(h.numberOfAged19_60_disabled_info, Disable.JINGSHEN.name)){
            disable_style = Disable.JINGSHEN.flag;
        }else if(ArrayUtils.isContains(h.numberOfAged19_60_disabled_info, Disable.ZHITI.name)){
            disable_style = Disable.ZHITI.flag;
        }else if(ArrayUtils.isContains(h.numberOfAged19_60_disabled_info, Disable.SHILI.name)){
            disable_style = Disable.SHILI.flag;
        }else if(ArrayUtils.isContains(h.numberOfAged19_60_disabled_info, Disable.TINGLI.name)){
            disable_style = Disable.TINGLI.flag;
        }else if(ArrayUtils.isContains(h.numberOfAged19_60_disabled_info, Disable.YANYU.name)){
            disable_style = Disable.YANYU.flag;
        }

        other_housing = m.villageHousing;

        if(two.other_house_area.contains("80-120")){
            other_house_area = 2;
        }else if (two.other_house_area.contains("80")){
            other_house_area = 1;
        }else if (two.other_house_area.contains("120")){
            other_house_area = 3;
        }

        car_number = two.car_number;

        financialAssets = three.propertyIncome.equityInterest;

        alimony = three.transferIncome.alimony;

        //人均收入(含补助)
        perCapitaIncome = i.perIncomeTotal;

        //人均收入（不含补助）
        perCapitaIncomeN = (i.totalRevenue - three.transferIncome.groundSubsidy - three.transferIncome.forestrySubsidy
        - three.transferIncome.landSubsidies - three.transferIncome.livingAllowances
        - three.transferIncome.scholarship)/one.total_people_num;

        individualBusinessIncome = three.operatingIncome.selfEmployedOucome;

        educationOutCome = four.necessaryExpenses.educationOutCome;

        bigHealthSpending = four.necessaryExpenses.bigHealthSpending;

        bigPersonMoney = four.necessaryExpenses.bigPersonMoney;

        slowPersonMoney = four.necessaryExpenses.slowPersonMoney;

        emergentEventMoney =four.suddenExpenditure.emergentEventMoney;

        perHouseholdExpenditure = (o.dailyConsumptionExpenditure + o.necessaryRigidExpenditure
                + o.socialExpenditure + o.suddenExpenditure)/one.total_people_num;

        perExpenditure = o.perCapitaNetIncome;

        minLivingSecurity = info.minimum_living_level * 12;

        //人均收入（不含补助）-最低生活保障
        minLivingSecurity_ = perCapitaIncomeN - minLivingSecurity;

        minLivingSecurity__ = perExpenditure - minLivingSecurity;

        minLivingSecurity___ = perExpenditure - 1.5 * minLivingSecurity;

        stock = three.propertyIncome.equityInterest
                + three.propertyIncome.realEstateRent
                + three.propertyIncome.financialDividends;

        disabilitiesNumber = h.disability;

        //计算权值
        laborNumber = getDetTwo(h.laborAssignment*8.28);

        laborProportion = getDetTwo(h.mainForceAssignment*4.06);

        educationLevel = getDetTwo(h.educationalAssignment*2.71);

        healthStatus = getDetTwo(h.healthAssignment*22.36);

        employmentStatus = getDetTwo(h.employmentAssignment*5.59);

        homesteadNumber = getDetTwo(n.homesteadsAssignment*1.80);

        cultivatedLandResources = getDetTwo(n.cultivatedAssignment*3.60);

        forestResources = getDetTwo(n.forestAssignment*3.60);

        housingSource = getDetTwo(m.housingSourceAssignment*5.18);

        housingArea = getDetTwo(m.housingAreaPerAssignment*2.93);

        additionalPurchase = getDetTwo(m.villageHousingAssignment*3.15);

        durableGoods = getDetTwo(m.durableGoodsAssignment*3.75);

        operatingIncome = getDetTwo(i.perOperatingIncomeAssignment*5.28);

        wageIncome = getDetTwo(i.perWageIncomeAssignment*10.56);

        transferIncome = getDetTwo(i.perTransferIncomeAssignment*3.52);

        propertyIncome = getDetTwo(i.perPropertyIncomeAssignment*2.64);

        groupCadres = getDetTwo(s.villageCadreAssignment*1.53);

        getHelp = getDetTwo(s.helpAssignment*0.75);

        dailyCommunicationExpenses = getDetTwo(o.dailyCommunicationAssignment*3);

        socialOrganizations = getDetTwo(s.socialAssignment*1.77);

        socialInsurance = getDetTwo(o.endowmentInsuranceAssignment*0.87);

        discountLoan = getDetTwo(s.policyLoanAssignment*0.26);

        borrowMoney = getDetTwo(s.borrowMoneyAssignment*1.06);

        humanExpenditure = getDetTwo(o.socialInteractionAssignment*0.44);

        numberOfOutsiders = getDetTwo(s.socialTimesAssignment*1.32);

        result = getDetTwo(laborNumber + laborProportion + educationLevel
                + healthStatus + employmentStatus + homesteadNumber
                + cultivatedLandResources + forestResources + housingSource
                + housingArea + additionalPurchase + durableGoods
                + operatingIncome + wageIncome + transferIncome
                + propertyIncome + groupCadres + getHelp
                + dailyCommunicationExpenses + socialOrganizations
                + socialInsurance + discountLoan + borrowMoney
                + humanExpenditure + numberOfOutsiders);

        System.out.println("综合评分为："+ result);
    }



    double getDetTwo(double num){
        return Double.parseDouble(String.format("%.2f", num));
    }
}
